package com.itheima.aop;

import lombok.extern.slf4j.Slf4j;
import org.aspectj.lang.ProceedingJoinPoint;
import org.aspectj.lang.annotation.Around;
import org.aspectj.lang.annotation.Aspect;
import org.aspectj.lang.annotation.Before;
import org.aspectj.lang.annotation.Pointcut;
import org.springframework.stereotype.Component;

/**
 * @author zhangbaiyan
 * @date 2024-10-02 16:26
 * @description:
 * @version:
 */
@Slf4j
@Aspect
@Component
public class MyAspect2 {



    //原始方法执行前
    @Before("com.itheima.aop.MyAspect1.pointCut()")//("execution(* com.itheima.service.impl.DeptServiceImpl.*(..))")
    public void before() {
        log.info("before...");
    }

    //环绕原始方法执行
    @Around("com.itheima.aop.MyAspect1.pointCut()")//("execution(* com.itheima.service.impl.DeptServiceImpl.*(..))")
    public Object around(ProceedingJoinPoint joinPoint) throws Throwable {
        log.info("around...before");
        //1.获取目标对象的类名
        String className = joinPoint.getTarget().getClass().getName();
        log.info("around...className:{}",className);
        //2.获取目标对象的方法名
        String methodName = joinPoint.getSignature().getName();
        log.info("around...methodName:{}",methodName);
        //3.获取目标方法运行时传入的参数
        Object[] args = joinPoint.getArgs();
        log.info("around...args:{}",args);
        //4.放行目标方法执行
        Object res = joinPoint.proceed();
        log.info("around...res:{}",res);
        //5.获取目标方法运行的返回值
        log.info("around...res:{}",res);
        log.info("around...after");
        return res;
    }
}
